package com.rong.maven01demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rong.maven01demo.dao.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * mybatis plus 简化了单表查询，如果遇到多表查询的情况还是要用mybatis解决：
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    /**
     * 一对多用many
     * 一对一用one  --同样是one = @One(...)
     *
     * many使用查到的数据库字段作为参数，传入@Many的select方法
     * @return
     */
    @Select("select * from t_user")
    @Results({
            @Result(column = "sid", property = "sid"),
            @Result(column = "sname", property = "sname"),
            @Result(column = "nage", property = "nage"),
            @Result(column = "username", property = "username"),
            @Result(column = "password", property = "password"),
            @Result(column = "sid", property = "roles", javaType = List.class,
                    many = @Many(select = "com.rong.maven01demo.mapper.RoleMapper.selectByUserId")
            )
    })
    List<User> selectUsers();

    @Insert("insert into t_user values(#{sid},#{susername},#{nage},#{username},#{password}) ")
    int insert(User user);
}
